#!/bin/bash
set -e

while getopts  ":s:p:" opts
do
        case  $opts  in
        s)
		barcode=$OPTARG
		sample_name=$OPTARG
		
		;;
		p)
		out_prefix=$OPTARG
		
		;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-p out_prefix] reads1.fq[.gz] reads2.fq[.gz]'
	exit 1
fi


#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------


truseq_uni_res_com_22=AGATCGGAAGAGCGTCGTGTAG
truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT



truseq_0_22=GATCGGAAGAGCACACGTCTGA
# truseq_0_20=GATCGGAAGAGCACACGTCT
truseq_0_20=AGATCGGAAGAGCACACGTC

primer5maltic=GTGAGTGATGGTTGAGGTAGTGTGGAG
primer5maltic20=ATGGTTGAGGTAGTGTGGAG

primer3maltic=CTCCACACTACCTCAACCATCACTCAC
primer3maltic20=CTCCACACTACCTCAACCAT

tem_seq1=TGGAATTCTCGGGTGCCAAG

tem_seq2=AGATCGGAAGAGCGTCGT



# 插入序列和前向引物序列长度不大于 300bp，理应有 adaptor 存在，
# 所以选择 overlap=7 


# If you use any of the filtering options, you must use cutadapt in the following way (with the -p option) to make sure that read pairs remain sychronized.
# 使用过滤参数的话，reads1 reads2 需要分开处理

# ${tools_path}/Python-2.7.10/python \
# $cutadapt \
# -u +19 \
# -u -20 \
# -m 80 \
# -e 0.12 \
# --overlap 7 \
# -a $truseq_0_20 \
# -o $out_prefix.1.tmp.fastq \
# -p $out_prefix.2.tmp.fastq \
# --discard-untrimmed \
# $1 \
# $2

# ${tools_path}/Python-2.7.10/python \
# $cutadapt \
# -u +19 \
# -u -20 \
# -m 80 \
# -e 0.12 \
# --overlap 7 \
# -a $truseq_uni_res_com_20 \
# -o $out_prefix.2.cut.fastq \
# -p $out_prefix.1.cut.fastq \
# --discard-untrimmed \
# $out_prefix.2.tmp.fastq \
# $out_prefix.1.tmp.fastq

${tools_path}/Python-2.7.10/python \
$cutadapt \
-u +19 \
-u -20 \
-m 80 \
-e 0.12 \
--overlap 7 \
-a $truseq_0_20 \
-o $out_prefix.1.tmp.fastq \
-p $out_prefix.2.tmp.fastq \
$1 \
$2

${tools_path}/Python-2.7.10/python \
$cutadapt \
-u +19 \
-u -20 \
-m 80 \
-e 0.12 \
--overlap 7 \
-a $truseq_uni_res_com_20 \
-o $out_prefix.2.cut.fastq \
-p $out_prefix.1.cut.fastq \
--discard-untrimmed \
$out_prefix.2.tmp.fastq \
$out_prefix.1.tmp.fastq



. $cmd_done
# --discard-untrimmed \
# --untrimmed-output=$out_prefix.1.untri.fastq \
# --untrimmed-paired-output=$out_prefix.2.untri.fastq \





# len5=27
# len3=25




# seqtk trimfq -b $len5 $out_prefix.1.cut.fastq > $out_prefix.1.trimmed.fastq
# seqtk trimfq -b $len5 $out_prefix.2.cut.fastq > $out_prefix.2.trimmed.fastq
